package com.dcm.seckill.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.common.annotation.IgnoreResponseBodyAdvice;
import com.dcm.seckill.entity.SeckillEntity;
import com.dcm.seckill.service.SeckillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @author 牛浩
 */
@Api(tags = "SeckillController")
@RestController
@RequestMapping("/seckill")
@CrossOrigin
@EnableResponseBodyAdvice
public class SeckillController {
    @Autowired
    private SeckillService seckillService;

    /**
     * 查询所有
     * @return
     */
    @ApiOperation("查询所有")
    @GetMapping("/findAll")
    public List<SeckillEntity> findAll(){
        return seckillService.findAll();
    }

    /**
     * 点击状态根据id修改状态
     * @param mid
     */
    @ApiOperation("点击状态根据id修改状态")
    @GetMapping("/updateState")
    public void updateState(@RequestParam( value = "mid" ,required=false) Long mid){
        seckillService.updateState(mid);
    }

    /**
     * 根据id查询一条数据
     * @RequestParam mid
     * @return
     */
    @ApiOperation("根据id查询一条数据")
    @GetMapping("/findOne")
    public SeckillEntity findOne(@RequestParam(value = "mid",required = false)Long mid){
       return seckillService.findOne(mid);
    }

    /**
     * 修改
     * @param miaosha
     */
    @ApiOperation("修改")
    @PutMapping("/update")
    public void update(@RequestBody SeckillEntity miaosha){
        seckillService.update(miaosha);
    }

    /**
     * 删除
     * @param mId
     */
    @ApiOperation("删除")
    @GetMapping("/delete")
    public void delete(@RequestParam(value = "mId",required = false) Long mId){
        seckillService.delete(mId);
    }

    /**
     * 添加
     * @param miaosha
     */
    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(@RequestBody SeckillEntity miaosha){
        seckillService.add(miaosha);
    }

    /**
     * 模糊查询
     * @param state
     * @param name
     * @return
     */
    @ApiOperation("模糊查询")
    @GetMapping("/search")
    public List<SeckillEntity> search(@RequestParam(value = "state",required = false) Integer state,
                                      @RequestParam(value = "name",required = false) String name){
        return seckillService.search(state,name);
    }

}
